<?php
require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
            'appId' => '171726412964671',
            'secret' => '0ff931e6b5bab347a178de0b3a78fc4a',
        ));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
        $user = null;
    }
}
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
        <title>Compare Anything</title>
        <?php include 'includes.php'; ?> 
    </head>
    <body>
        <?php include 'header.php'; ?> 
        
        <div id="fb-root"></div>
        <script>
            window.fbAsyncInit = function() {
                FB.init({
                    appId: '<?php echo $facebook->getAppID() ?>',
                    cookie: true,
                    xfbml: true,
                    oauth: true
                });
                FB.Event.subscribe('auth.login', function(response) {
                    window.location.reload();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    window.location.reload();
                });
            };
            (function() {
                var e = document.createElement('script'); e.async = true;
                e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js';
                document.getElementById('fb-root').appendChild(e);
            }());
        </script>
    </body>
</html>